# coding=utf8
import os
from django.shortcuts import render
from django.http import JsonResponse, HttpResponse

path = os.path.abspath('') + '/'


# Create your views here.
def index_html(request):
    dirs = os.listdir(path + 'file/static')
    dirs.remove('iso')
    dirs.remove('影视')
    dirs.sort()
    data = {'List': dirs}
    return render(request, 'index.html', data)


def video_html(request):
    dirs = os.listdir(path + 'file/static/影视')
    dirs.sort()
    data = {'List': dirs}
    return render(request, 'video.html', data)


def iso_html(request):
    dirs = os.listdir(path + 'file/static/iso')
    dirs.sort()
    data = {'List': dirs}
    return render(request, 'iso.html', data)


def upload_file(request):
    recv_file = request.FILES.get('file')
    file_name = recv_file.name
    file_path = path + 'file/static/{}'.format(file_name)
    # if os.path.exists(file_path):
    #     return HttpResponse('该文件已存在')
    save_file = open(file_path, 'wb')
    for data in recv_file.chunks():
        save_file.write(data)
    save_file.close()
    return HttpResponse('操作完成')
